package com.swsm.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.swsm.domain.PaperState;
import com.swsm.domain.State;
import com.swsm.mapping.PaperMapper;
import com.swsm.mapping.PaperStateMapper;
import com.swsm.mapping.StateMapper;
import com.swsm.model.bean.B2SPaperPageBean;
import com.swsm.model.bean.B2SPaperReviewBean;
import com.swsm.service.PaperService;

@Service
public class PaperServiceImpl implements PaperService {
	
	@Autowired
	private PaperMapper mapper;
	@Autowired
	private PaperStateMapper paperStateMapper;
	@Autowired
	private StateMapper stateMapper;
	
	@Override
	public void paperReview(B2SPaperReviewBean bean) {
		State stateRecord = new State();
		stateRecord.setName(bean.getState());
		List<State> stateList = stateMapper.selectByExample(stateRecord);
		PaperState paperStateRecord = new PaperState();
		paperStateRecord.setId(bean.getPaper());
		List<PaperState> paperStateList = paperStateMapper.selectByExample(paperStateRecord);
		paperStateRecord = paperStateList.get(0);
		paperStateRecord.setState(stateList.get(0).getId());
		paperStateRecord.setOpinion(bean.getOpinion());
		paperStateMapper.updateByPrimaryKeySelective(paperStateRecord);
	}

	@Override
	public List getAllPaper(B2SPaperPageBean bean) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<>();
		map.put("skips", (bean.getPages()-1)*bean.getLimits());
		map.put("limits", bean.getLimits());
		map.put("rank", bean.getRank());
		map.put("grade", bean.getGrade());
		map.put("clazz", bean.getClazz());
		map.put("no", bean.getNo());
		map.put("name", bean.getName());
		return mapper.getAllPaper(map);
	}

}
